import java.util.HashSet;
import java.util.Objects;

/**
 * @author : Bruce
 * @date: 2024/7/21 - 07 - 21 - 21:41
 * @Description: PACKAGE_NAME
 * @version: 1.0
 */
public class TestSet {
    //这是main方法，程序的入口
    public static void main(String[] args) {
        //创建一个HashSet集合：
        HashSet<Student> hs = new HashSet<>();
//        hs.add("hello");
//        hs.add("apple");
//        hs.add("banana");
//        hs.add("html");
//        hs.add("apple");
//        hs.add("css");
//        System.out.println(hs.size());
//        System.out.println(hs);
        hs.add(new Student("yzh", 10));
        hs.add(new Student("yzh", 10));
        System.out.println(hs);
        System.out.println(hs.size());
    }
}

class Student {
    String name;
    Integer age;

    public Student(String name, Integer age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return Objects.equals(name, student.name) &&
                Objects.equals(age, student.age);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age);
    }
}